<%-- 
    Document   : Employee
    Created on : May 9, 2012, 9:28:43 AM
    Author     : Nguyen Hung
--%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@taglib prefix="rich" uri="http://richfaces.org/rich" %>
<%@taglib prefix="a4j" uri="http://richfaces.org/a4j" %>
<html>
    <head>

        <script type="text/javascript" language="javascript" src="../scripts/jQuery/confirm.js"></script>
        <script type="text/javascript" language="javascript" src="../scripts/jQuery/jquery.fancybox-1.3.4.pack.js"></script>
        <!-- -->
        <link rel="stylesheet" type="text/css" href="../scripts/tabs/slidingtabs-horizontal.css">
        <script type="text/javascript" src="../scripts/tabs/slidetab.js"></script>
        <!-- -->
        <script type="text/javascript" language="javascript" src="../scripts/jQuery/jquery.rateit.js"></script>
        <script src="../scripts/dialog/jquery.alerts.js" type="text/javascript"></script>
        <link href="../scripts/dialog/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" />
        <link rel="stylesheet" type="text/css" href="../css/rateit.css">
        <script type="text/javascript" language="javascript">
            var open_cur = 0;
            $j = jQuery.noConflict();
            function PrintElem()
            {
                Popup($j(".around_tour").html());
            }

            function Popup(data) 
            {
                var mywindow = window.open('', 'my div', 'height=800,width=650');
                mywindow.document.write('<html><head><title>SGT-QUEENB</title>');
                mywindow.document.write('<link rel="stylesheet" href="../css/kapiform.css" type="text/css" />');
                mywindow.document.write('<script type="text/javascript" src="../scripts/jQuery/test.js">');
                mywindow.document.write('<\/script>');
                mywindow.document.write('</head><body >');
                mywindow.document.write(data);
                mywindow.document.write('</body></html>');

                mywindow.print();
                mywindow.close();

                return true;
            }

            $j(document).ready(function(){ 
                var regex = /^(.*)(\d)+$/i;
                var cloneIndex = $j(".content_tour").length;
                var appendIndex = $j(".tour_bottom_content").length;
               
                $j(".print").live("click",function(){
                    PrintElem();
                });
               
                $j(".clone").live("click", function(){
                    number_person= $j(".number_person").val();
                    
                    len = number_person.length;
                   
                    if(len== 0||(isNaN(number_person))){
                       
                        $j(".erro").text("Lỗi nhập liệu ! Xin vui lòng kiểm tra lại dữ liệu hệ thống !");                     
                       
                    }else{
                        tempate_row3='';
                        tempate_row3+='<form  class="demo demo[]" action="/KAPI/queenb/index/managerTour.jsp" method="post" name="demo1" target="">';
                        cloneIndex++;
                        
                        $j(this).parents(".content_tour").clone()
                        .appendTo(".around_tour")
                        .attr("id", "content_tour" +  cloneIndex)
                        .find("*").each(function() {
                            var id = this.id || "";
                            var match = id.match(regex) || [];
                            if (match.length == 3) {
                                this.id = match[1] + (cloneIndex);
                            }
                        });
                      
                        
                        $j(".erro").text("");
                    }
                });


                $j(".remove").live("click", function(){
               
                  //  $j(this).parents(".content_tour").remove();
                });
                $j(".tour_row7").live("click", function(){
                    s1 =  $j(this).prev(".tour_row5").text();
                    s2 = $j(this).parent(".tour_bottom_content").parent(".tour_bottom_content_parent").next(".tour_bottom_content").next(".tour_bottom_content_sum").find(".sumAll").text()
                    $j(this).parent(".tour_bottom_content").parent(".tour_bottom_content_parent").next(".tour_bottom_content").next(".tour_bottom_content_sum").find(".sumAll").text(parseFloat(s2)-parseFloat(s1));
                    sumAll = parseFloat(s2)-parseFloat(s1);
                    number_person_remove = $j(this).parents().find(".number_person").val();
                    
                    divnetidremove = parseFloat(sumAll)/parseFloat(number_person_remove);
                    $j(this).parents().find(".divnet").text(divnetidremove);
                  
                    $j(this).parents(".tour_bottom_content").remove();
                    
                 
                });
                
                $j("#confirm_button").click( function() {
                    jConfirm('Can you confirm this?', 'Confirmation Dialog', function(r) {
						
                    });
                });
                
                //---------------------------------------------------------------
                var sums=0;
                a=0;b=0;
                $j(".expenseInput").live("keyup",function(){
                    a = $j(".expenseInput").val();
                    b = $j(".qualityInput").val();
               
                    sums =parseFloat(a)*parseFloat(b);
                    $j(".sumInput").text(sums);
                });
                $j(".qualityInput").live("keyup",function(){
                    a = $j(".expenseInput").val();
                    b = $j(".qualityInput").val();
                    sums =parseFloat(a)*parseFloat(b);
                    $j(".sumInput").text(sums);
                });
                
               
             
                var i = 0;
                var sum = 0;
                var sumAll  = 0;
                var sumAllID = 0;
                var sumnet = 0;
             
                $j(".tour_row6").live("click",function(){
                
                    limit_entry = $j(this).parent().find('.tour_row1').children('.service1').children('option:selected').text();
                    expense = $j(this).parent().find('.tour_row2').children(".expenseInput").val();
                    money = $j(this).parent().find('.tour_row3').children(".moneyInput").children('option:selected').text();
                    quality = $j(this).parent().find('.tour_row4').children(".qualityInput").val();
                    sum = parseFloat(expense)*parseFloat(quality);                
                    sumAll = parseFloat(sumAll)+ parseFloat(sum);
                    sumAllID = $j(this).parent().next(".tour_bottom_content_sum").find('.sumAll').text(sumAll);
                    var idnet = $j(this).parent(".tour_bottom_content").next(".tour_bottom_content_sum").children(".net").children(".divnet").text();
                    
                    person_numberid = $j(this).parent(".tour_bottom_content").prev(".tour_bottom_content_parent").parent(".content_tour_bottom_parent_content_ssum").parent(".content_tour_bottom").prev(".content_tour_top").children(".content_tour_top_left").children(".tour_input_feild").find(".number_person").val();
                    
                    sumnet = parseFloat(sumAll)/parseFloat(person_numberid);                   
                     
                    $j(this).parent(".tour_bottom_content").next(".tour_bottom_content_sum").children(".net").children(".divnet").text(sumnet);
                    
                    template_row2='';
                    template_row2+='        <div class="tour_bottom_content[] tour_bottom_content" id="tour_bottom_content1">';
                    template_row2+='            <div class="tour_row1">';
                    template_row2+='                <h:outputText value="'+limit_entry+'" styleClass="limit_entry[] limit_entry" id="limit_entry1" />';
                    template_row2+='            </div>';                    
                    template_row2+='            <div class="tour_row2" >';
                    template_row2+='               <h:outputText value="'+expense+'" style="text-align:right;" styleClass="expense expense[]" id="expense1" />';
                    template_row2+='            </div>';
                    
                    template_row2+='            <div class="tour_row3">';    
                    template_row2+='               <h:outputText value="'+money+'" styleClass="money money[]" id="money1" />';
                    template_row2+='            </div>';
                    
                    template_row2+='            <div class="tour_row4">';
                    template_row2+='               <h:outputText value="'+quality+'" style="text-align:right;" styleClass="quality quality[] " id="quality1"/>';
                    template_row2+='            </div>';
                    
                    template_row2+='            <div class="tour_row5">';
                    template_row2+='               <h:outputText value="'+sum+'" styleClass="sum sum[]" id="sum1" style="text-align:right;" />';
                    template_row2+='            </div>';
                    
                    template_row2+='            <div class="tour_row7 tour_row7[]" id="tour_row7">';
                    template_row2+='               <img src="../images/delete_1.png" alt=""/>';
                    template_row2+='            </div>';
                   
                    template_row2+='        </div>';
                    
                    appendIndex++;
                    if(!isNaN(expense)&&(!isNaN(quality))){
                        $j(this).parent().prev("div.tour_bottom_content_parent").append(template_row2)               
                        //$j(".tour_bottom_content_parent").append(template_row2)                        
                        .attr("id", "tour_bottom_content" +  appendIndex+i)
                        .find("*").each(function() {
                            var id = this.id || "";
                            var match = id.match(regex) || [];
                            if (match.length == 3) {
                                this.id = match[1] + (appendIndex);
                            }
                        });
                       
                        appendIndex++;
                        i++;
                        $j(".erro").text("");
                    }else{
                        $j(".erro").text("Lỗi nhập liệu ! Xin vui lòng kiểm tra lại dữ liệu hệ thống !");
                    }
                   
              
                });
                $j(".price_buy").live("change",function(){
                    netprev = $j(this).parent(".business_bottom_row_name").parent(".business_bottom_row1").parent(".tour_bottom_content_business_bottom").parent(".tour_bottom_content_business").parent(".tour_bottom_content_business_speci").prev(".content_tour_bottom_parent_content_ssum").children(".tour_bottom_content_sum").children(".net").find(".divnet").text();
                    priceprev = $j(this).val();
                
                });
               
              
            });
             
                
        </script>
        <style>

            .chare_content .chare_content_head{
                background:#586C7F; 
                float:left;
                height: 12px;
                padding:8px;
                width:100%;

            }
            .chare_content .chare_content_head span{
                font-size: 12px;
                color:#fff;
                font-weight: bold;

                text-transform: uppercase;
            }
        </style>

    </head>


    <body>
        <f:loadBundle basename="#{environmentSession.localizationSource}" var="locale"/>
        <div id="content">
            <div id="menu_top">
                <div class="dropdown">
                    <div class="select_choise">
                        <a href="#"><span>Khu vực</span></a>
                    </div>
                    <div class="select_hidden">
                        <ul>

                            <li><a href="#"><span>Filter Cấp 3</span></a></li>
                            <li><a href="#"><span>Filter Cấp 3</span></a></li>
                        </ul>
                    </div>
                </div>
                <div class="dropdown">
                    <div class="select_choise">
                        <a href="#"><span>Outlets</span></a>
                    </div>
                    <div class="select_hidden">
                        <ul>
                            <li><a href="#"><span>Ban Điều Hành</span></a></li>
                            <li><a href="#"><span>Nhóm IT</span></a></li>
                            <li><a href="#"><span>Filter Cấp 3</span></a></li>
                        </ul>
                    </div>
                </div>
            </div>
            <div id="content_detail">
                <div class="sidebar">
                    <a href="customerInput.jsp?action=addEmp&table=A&height=300px&width=400px" class="fancybox add_new" id="fancybox">
                        <span><h:outputText value="#{locale.addCustomer}"/>
                        </span>
                    </a>

                    <div class="search_box">
                        <form action="" method="get">
                            <h3><h:outputText value="#{locale.search}"/></h3>
                            <div class="fields_input">
                                <input name="" type="text"  value="Tìm theo từ khoá..." onblur="if(this.value=='')this.value='Tìm theo từ khoá...';" onfocus="if(this.value=='Tìm theo từ khoá...')this.value='';" />
                                <input name="" type="submit" value="OK" />
                            </div>
                        </form>
                        <h4><h:outputText value="#{locale.advance_search}"/></h4>
                        <div class="fields_select">
                            <select name="">
                                <option><h:outputText value="#{locale.group}"/> / <h:outputText value="#{locale.Departments}"/></option>
                            </select>
                        </div>
                        <div class="fields_select">
                            <select name="">
                                <option>Giới tính...</option>
                            </select>
                        </div>
                        <div class="fields_select">
                            <select name="">
                                <option>Chức vụ...</option>
                            </select>
                        </div>
                        <div class="fields_select">
                            <select name="">
                                <option>Thu nhập...</option>
                            </select>
                        </div>
                        <div class="fields_submit">
                            <input name="" type="submit" value="Tìm chọn" />
                        </div>
                    </div>
                </div>
                <div class="content_right">
                    <div class="fillter">
                        <h:form>
                            <div class="dropdown">
                                <div class="select_choise">
                                    <h:outputLink value="workChargeCM.jsp"><span><h:outputText value="#{locale.individuals}"/></span>
                                        <f:param value="customer.jsp" name="page"></f:param>
                                    </h:outputLink>
                                </div>
                                <div class="select_hidden">
                                    <ul>
                                        <li> <h:outputLink value="workChargeCOM.jsp"><span><h:outputText value="#{locale.company}"/></span>
                                                <f:param value="cuscompany.jsp" name="page"></f:param>
                                            </h:outputLink>
                                        </li>

                                    </ul>
                                </div>
                            </div>
                        </h:form>
                    </div>

                    <div class="content">

                        <!-- Strart list Content -->
                        <div class="list_content">
                            <div class="chare_content">
                                <div class="chare_content_head"><span>Quản lý Tour</span></div>
                            </div>
                            <div class="print"><img src="../images/printer.png" alt=""/></div>
                            <div class="around_tour">

                                <!-- start content tour-->
                                <div class="code_tour">
                                    <label style="margin-left:-23px;">Tour:</label>
                                    <h:selectOneMenu value="#{TourBean.fs200}">                                           
                                        <f:selectItems value="#{TourBean.listItemS200}"/>                                          
                                    </h:selectOneMenu>
                                </div>

                                <div class="erro"></div>
                                <div id="content_tour1" class="content_tour content_tour[]">
                                    <a4j:form id="demo1" styleClass="demo[] demo">
                                        <div class="content_tour_top" style="height:30px;">
                                            <div class="content_tour_top_left">
                                                <div class="tour_input_feild">
                                                    <label>Số lượng:</label>
                                                    <h:inputText  value="#{TourBean.vn511}" styleClass="number_person number_person[]" id="number_person1" style="width:50px !important;height: 20px;" />
                                                </div>
                                                <div class="tour_input_feild">
                                                    <label>HDV:</label>
                                                    <h:inputText value="" style="width:50px !important;height: 20px;"/>
                                                </div>
                                            </div>

                                        </div>
                                        <div class="content_tour_bottom">
                                            <div class="content_tour_bottom_parent_content_ssum">
                                                <div class="tour_bottom_content_parent">
                                                    <div class="tour_bottom_head">
                                                        <div class="tour_row1">Hạn mục</div>
                                                        <div class="tour_row2">Phí</div>
                                                        <div class="tour_row3">Ngoại tệ</div>
                                                        <div class="tour_row4">Số lượng</div>
                                                        <div class="tour_row5">Tổng</div>
                                                        <div class="tour_row6"></div>
                                                    </div>
                                                </div>
                                                <a4j:repeat id="rerender" value="#{TourBean.orderList}" var="item">
                                                    <div class="tour_bottom_content[] tour_bottom_content" id="tour_bottom_content1">
                                                        <div class="tour_row1">
                                                            <h:outputText value="#{item.fv200}" styleClass="limit_entry[] limit_entry" id="limit_entry1" />
                                                        </div>                    
                                                        <div class="tour_row2" >
                                                            <h:outputText value="#{item.vn508}" style="text-align:right;" styleClass="expense expense[]" id="expense1" />
                                                        </div>

                                                        <div class="tour_row3">    
                                                            <h:outputText value="#{item.vv506}" styleClass="money money[]" id="money1" />
                                                        </div>

                                                        <div class="tour_row4">
                                                            <h:outputText value="#{item.vn507}" style="text-align:right;" styleClass="quality quality[] " id="quality1"/>
                                                        </div>

                                                        <div class="tour_row5">
                                                            <h:outputText value="#{item.vn509}" styleClass="sum sum[]" id="sum1" style="text-align:right;" />
                                                        </div>
                                                        <%--
                                                                                                                <div class="tour_row7 tour_row7[]" id="tour_row7">
                                                                                                                    <img src="../images/delete_1.png" alt=""/>
                                                                                                                </div>
                                                        --%>
                                                        <a4j:commandLink reRender="demo" value="Delete" 
                                                                         action="#{TourBean.deleteAction(item)}" />
                                                    </div>
                                                </a4j:repeat>
                                                <div class="tour_bottom_content">
                                                    <div class="tour_row1">   
                                                        <h:selectOneMenu value="#{TourBean.fv200}" id="service1" styleClass="service1 service[]">
                                                            <f:selectItems id="option1"  value="#{TourBean.listItemV200}"/>
                                                        </h:selectOneMenu>
                                                    </div>
                                                    <div class="tour_row2" >
                                                        <h:inputText value="#{TourBean.vn508}" styleClass="expenseInput[] expenseInput" id="expenseInput1" style="height: 20px;" />
                                                    </div>
                                                    <div class="tour_row3">    
                                                        <h:selectOneMenu id="moneyInput1" styleClass="moneyInput moneyInput[]" value="#{TourBean.vv506}"  style="height: 20px;">
                                                            <f:selectItem itemLabel="USD" itemValue="1"/>
                                                            <f:selectItem itemLabel="VN" itemValue="2"/>                                                            
                                                        </h:selectOneMenu>
                                                    </div>
                                                    <div class="tour_row4">
                                                        <h:inputText value="#{TourBean.vn507}" styleClass="qualityInput[] qualityInput" id="qualityInput1" style="height: 20px;"/>
                                                    </div>

                                                    <div class="tour_row5">
                                                        <h:outputText value="" styleClass="sumInput sumInput[]" id="sumInput1" style="height: 20px;"/>
                                                    </div>
                                                    <%--
                                                    <div class="tour_row6[] tour_row6" id="tour_row6">
                                                       
                                                    </div> --%>
                                                    <a4j:commandButton  value="Add" reRender="demo1" styleClass="add[] add" action="#{TourBean.addAction}" >

                                                    </a4j:commandButton>
                                                </div>

                                                <div class="tour_bottom_content_sum">
                                                    <div class="content_sum_label">Tổng:</div>
                                                    <div class="content_sum_number"><h:outputText value="#{TourBean.sumAll}" styleClass="sumAll sumAll[]" id="sumAll1"/> VND</div>
                                                    <div class="net net[]" id="net1">
                                                        <label><h:outputText value="NET"/></label>
                                                        <h:outputText value="#{TourBean.sumNet}" id="divnet1" styleClass="divnet divnet[]" />
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="tour_bottom_content_business_speci">
                                                <div class="tour_bottom_content_business">
                                                    <div class="tour_bottom_content_business_head">
                                                        <label style="margin-top: 5px;">Kinh Doanh:</label>

                                                    </div>
                                                    <div class="tour_bottom_content_business_bottom">
                                                        <div class="business_bottom_row1">
                                                            <div class="business_bottom_row_title"><h:outputText value="Giá bán:"/></div>
                                                            <div class="business_bottom_row_name"><h:inputText value="#{TourBean.vn510}" id="price_buy1" styleClass="price_buy price_buy[]"/></div>
                                                        </div>
                                                        <div class="business_bottom_row2">
                                                            <div class="business_bottom_row_title"><h:outputText value="Lãi gộp:"/></div>
                                                            <div class="business_bottom_row_name"><h:outputText value="#{TourBean.laigop}"/></div>
                                                        </div>
                                                        <div class="business_bottom_row3">
                                                            <div class="business_bottom_row_title"><h:outputText value="Tỉ lệ:"/></div>
                                                            <div class="business_bottom_row_name"><h:outputText value="#{TourBean.tile}"/></div>
                                                        </div>
                                                        <div class="business_bottom_row4">
                                                            <div class="business_bottom_row_title"><h:outputText value="Profit:"/></div>
                                                            <div class="business_bottom_row_name"><h:outputText value="#{TourBean.profit}"/></div>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="tour_bottom_content_specific">
                                                    <div class="specific_duthu"> Dự thu:</div>
                                                    <div class="specific_number"> <h:outputText value="#{TourBean.duthu}"/></div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="actions" style="margin-top:-7px;">
                                            <div class="btn_add_tour  clone" ><img src="../images/add_tab.png" alt=""/></div>
                                            <div class="tour_right tour_right[] remove" id="tour_right1" ><img src="../images/delete_1.png" alt=""/></div>
                                        </div>
                                        <div class="btn_add_tour_content">
                                            <a4j:commandButton value="Luu Tour" reRender="demo" action="#{TourBean.saveTour}">

                                            </a4j:commandButton>
                                        </div>
                                    </a4j:form>
                                </div>


                                <!-- e nd content tour-->

                            </div>

                        </div>
                        <!-- End List Content-->    
                    </div>
                    <rich:modalPanel id="ajaxLoadingModalBox" minHeight="30" minWidth="40"
                                     height="30" width="40" zindex="2000">
                        <h:outputText value="Please wait" styleClass="startDummer"></h:outputText>
                    </rich:modalPanel>

                </div>
            </div>
        </div>

    </body>
</html>
